package com.specialtreasure.freightdepot.mq;

import android.content.Context;
import android.content.Intent;


import com.app.core.config.BaseConfig;
import com.app.core.config.Constants;
import com.app.core.util.UserUtils;
import com.specialtreasure.freightdepot.model.EventBean;
import com.specialtreasure.freightdepot.service.MQService;

import org.simple.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by KUMA on 2017/8/11.
 */
public class MQUtils {
    public static void connectMQ(Context context) {
        context.startService(new Intent(context, MQService.class));
    }

    public static void stopMQ(Context context) {
        context.stopService(new Intent(context, MQService.class));
    }

    //1.清除老队列，创建新队列
    public static void createQueue(Context context, String queueName, String routingKey, String tag) {
        Intent i = new Intent(context, MQService.class);
        MQueue q = new MQueue();
        q.queueName = queueName + UserUtils.getUserId();
        q.routingKeys = new ArrayList<>();
        q.routingKeys.add(routingKey);
        q.eventTag = tag;
        i.putExtra(MQService.INTENT_QUEUE, q);
        context.startService(i);
    }

    public static void createQueue(Context context, String queueName, List<String> routingKeys, String tag) {
        Intent i = new Intent(context, MQService.class);
        MQueue q = new MQueue();
        q.queueName = queueName + UserUtils.getUserId();
        q.routingKeys = routingKeys;
        q.eventTag = tag;
        i.putExtra(MQService.INTENT_QUEUE, q);
        context.startService(i);
    }

    //异步线程删除队列，后面不要跟创建队列
    public static void deleteQueue(Context context, String queueName) {
        EventBus.getDefault().post(new EventBean(Constants.MsgCode.ON_DELQUEUE, queueName + UserUtils.getUserId()), MQService.class.getName());
    }
}
